-- TURN HEADERS OFF set nocount on exec sp_msforeachdb 'if ''?'' not in (''master'',''model'',''msdb'',''tempdb'',''pubs'',''NorthWind'') begin use ? print ''-- ?'' print ''set nocount on'' select ''declare @dt datetime'' select ''exec sp_detach_db '' + db_name() GO'' end ' exec sp_msforeachdb 'if ''?'' not in (''master'',''model'',''msdb'',''tempdb'',''pubs'',''NorthWind'') begin use ? print ''-- ?'' print ''set nocount on'' select ''declare @dt datetime'' select ''exec sp_attach_db '' + db_name() + '', '''''' + rtrim(cast(filename as varchar(50))) + '''''', -- '' + cast(size*.008 as varchar(10)) + '' MB '' + (select '''''''' + rtrim(cast(filename as varchar(50))) + '''''' -- '' + cast(size*.008 as varchar(10)) + '' MB'' from sysfiles where fileid = 2) from sysfiles where fileid = 1 select ''exec sp_attach_db '' + db_name() + '', '''''' + rtrim(replace(cast(filename as varchar(50)), ''MSSQL7'', ''MSSQL'')) + '''''', '' + (select '''''''' + rtrim(replace(cast(filename as varchar(50)), ''MSSQL7'', ''MSSQL'')) + '''''''' from sysfiles where fileid = 2) from sysfiles where fileid = 1 GO'' end '